package Store;

import Product.ProductCatalog;
import Product.ProductReader;
import Transaction.Transaction;
import java.io.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.util.*;

public class Store implements Remote, Serializable {

    private String storeName;
    private String storeAddr;
    private ProductCatalog productCatalog;
    private List<Transaction> transactionLog;

    public Store( String storeName, String storeLocal){
        this.storeName = storeName;
        this.storeAddr = storeLocal;
        this.productCatalog = new ProductCatalog();
        this.transactionLog = new ArrayList<Transaction>() {};
    }

    public String getName(){ return this.storeName;}
    public String getAddr(){ return this.storeAddr;}

    public static void main(String[] args) throws IOException, RemoteException, AlreadyBoundException {
        Store theStore = new Store("The Store", "10 Downing St");
        ProductReader productReader = new ProductReader("products.txt");
        while (productReader.hasNextProduct()) { //Read products from product reader and add them to the store's product catalog
            theStore.productCatalog.addItem(productReader.getNextProduct());
        }
        Registry registry = LocateRegistry.getRegistry();
        registry.bind("Store", theStore);
    }

    public void recordSale(Transaction transaction) {
        this.transactionLog.add(transaction);
    }

    public ProductCatalog getProductCatalog() {
        return this.productCatalog;
    }

}
